package com.hzdesk.media.koreabatchmatvector.logic.view;

import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.AppCompatCheckBox;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.logic.contract.IWiredNetworkSettingsContract;
import com.hzdesk.media.koreabatchmatvector.logic.persenter.WiredNetworkSettingsPersenter;
import com.hzdesk.media.koreabatchmatvector.utils.IpUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/8/3.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public class WiredNetworkSettingsActivity extends BaseActivity implements IWiredNetworkSettingsContract.IWiredNetworkSettingsView {
    @BindView(R.id.activity_wire_net_work_setting_iv_back)
    ImageView activityWireNetWorkSettingIvBack;
    @BindView(R.id.activity_wire_net_work_setting_recylerview)
    RecyclerView activityWireNetWorkSettingRecylerview;
    @BindView(R.id.activity_wire_net_work_setting_checbox)
    AppCompatCheckBox activityWireNetWorkSettingChecbox;
    @BindView(R.id.activity_wire_net_work_setting_et_setting_ip)
    EditText activityWireNetWorkSettingEtSettingIp;
    @BindView(R.id.activity_wire_net_work_setting_et_setting_gateway)
    EditText activityWireNetWorkSettingEtSettingGateway;
    @BindView(R.id.activity_wire_net_work_setting_et_setting_dns)
    EditText activityWireNetWorkSettingEtSettingDns;
    @BindView(R.id.activity_wire_net_work_setting_tv_save)
    TextView activityWireNetWorkSettingTvSave;
    @BindView(R.id.activity_wire_net_work_setting_ll_setting_net_work)
    LinearLayout activityWireNetWorkSettingLlSettingNetWork;
    @BindView(R.id.activity_wire_net_work_setting_ll_bg)
    LinearLayout activityWireNetWorkSettingLlBg;

    private WiredNetworkSettingsPersenter mWiredNetworkSettingsPersenter = new WiredNetworkSettingsPersenter(this);
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wire_net_work_setting);
        ButterKnife.bind(this);

        mWiredNetworkSettingsPersenter.init(activityWireNetWorkSettingRecylerview,this);
        mWiredNetworkSettingsPersenter.setCheckBoxListening(activityWireNetWorkSettingChecbox,this);
        mWiredNetworkSettingsPersenter.setEditTextListening(activityWireNetWorkSettingEtSettingIp,this);
        mWiredNetworkSettingsPersenter.setEditTextListening(activityWireNetWorkSettingEtSettingGateway,this);
        mWiredNetworkSettingsPersenter.setEditTextListening(activityWireNetWorkSettingEtSettingDns,this);

    }

    @OnClick({R.id.activity_wire_net_work_setting_iv_back, R.id.activity_wire_net_work_setting_tv_save})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.activity_wire_net_work_setting_iv_back:
                mWiredNetworkSettingsPersenter.onClickedBack();
                break;
            case R.id.activity_wire_net_work_setting_tv_save:
                mWiredNetworkSettingsPersenter.onClickedSave();
                break;
        }
    }
    @Override
    protected void onStart() {
        super.onStart();
        final SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        int selector = mSharedPreferences.getInt("item_skin", 0); //todo 名称
        activityWireNetWorkSettingLlBg.setBackgroundResource(updateBg[selector]);
    }

    @Override
    public void finshPager() {
        finish();
    }

    @Override
    public void SaveConfigSettingDate() {

    }

    @Override
    public String getEtSettingIp() {
        return activityWireNetWorkSettingEtSettingIp.getText().toString().trim();
    }

    @Override
    public String getEtSettingGateway() {
        return activityWireNetWorkSettingEtSettingGateway.getText().toString().trim();
    }

    @Override
    public String getEtSettingDns() {
        return activityWireNetWorkSettingEtSettingDns.getText().toString().trim();
    }
    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void showSettingPager() {
        activityWireNetWorkSettingLlSettingNetWork.setVisibility(View.VISIBLE);
        activityWireNetWorkSettingEtSettingIp.setText(IpUtils.getLocalIp()+"");
        activityWireNetWorkSettingEtSettingDns.setText(IpUtils.getDns(this)+"");
       // IpUtils.getGateWay();

    }

    @Override
    public void hidenSettingPager() {
        activityWireNetWorkSettingLlSettingNetWork.setVisibility(View.GONE);

    }
    //网线的状态为  断开
    @Override
    public void wiredNetworkHidden() {
        super.wiredNetworkHidden();
        mWiredNetworkSettingsPersenter.cancel();
    }
    //网线的状态为  连上的
    @Override
    public void wiredNetworkShow() {
        super.wiredNetworkShow();

        mWiredNetworkSettingsPersenter.addEthernetInfo();
    }
}
